<template>
  <div class="photoList">
    <!-- 顶部滑动条 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            v-for="item in categoryList"
            :key="item.id"
            :class="['mui-control-item',item.id==0?'mui-active':'']"
            @click="getPhotoListBycategoryId(item.id)"
          >{{item.title}}</a>
          <!-- ,item.id==0?'mui-active':''  这个是设置 默认进去就是第一个高亮  切换的高亮是mui内部实现的-->
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul class="photo-list">
      <router-link v-for="item in photoList" 
      :key="item.id"
       tag="li"
       :to="'/home/photoinfo/'+item.id"
      >
        <img v-lazy="item.img_url" />
        <div class="info">
           <h3 class="info-title">{{item.title}}</h3>
           <div class="info-body">{{item.zhaiyao}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
 
<script>
//1.导入mui.js
import mui from "../../lib/mui/js/mui.min.js";
import { Toast } from "mint-ui";
export default {
  name: "",
  data() {
    return {
      categoryList: [],
      photoList: [],
    };
  },
  mounted() {
    this.getCategorys(),
      //默认进入页面,就主动请求全部图片
      this.getPhotoListBycategoryId(0),
      // 2.初始化滑动控件
      mui(".mui-scroll-wrapper").scroll({
        deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
      });
  },
  methods: {
    getCategorys() {
      this.$http.get("api/getimgcategory").then((res) => {
        if (res.body.status === 0) {
          //手动拼接出一个完整的分类列表
        //   console.log(res.body);
          res.body.message.unshift({ title: "全部", id: 0 });
          this.categoryList = res.body.message;
        } else {
          Toast("图片加载失败");
        }
      });
    },
    getPhotoListBycategoryId(categoryId) {
      //根据分类id,获取图片列表
      this.$http.get("api/getimages/" + categoryId).then((res) => {
        if (res.body.status === 0) {
        //   console.log(res.body.message);
          this.photoList = res.body.message;
        }
      });
    },
  },
};
</script>
 
<style scoped lang = "scss">
* {
  touch-action: pan-y;
}

.photo-list {
  margin: 0;
  padding: 10px;
  padding-bottom: 0;
  li {
    text-align: center;
    background-color: #ccc;
    list-style-type: none;
    margin-bottom: 10px;
    box-shadow: 0 0 10px #999;
  position: relative;

    img {
      width: 100%;
      vertical-align: middle;
      
    }
    .info{
        max-height: 84px;
        color: white;
        text-align: left;
        position: absolute;
        bottom: 0;
        background-color: rgba(0,0,0,.4);
        .info-title{
            font-size: 14px;
        }
        .info-body{
            font-size: 12px;
        }
    }
    /* 下面是懒加载图片不要动,不是真正的图片 */
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
}
</style>